package com.zhaoyan.okgorxjavademo;

import android.app.Application;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Handler;

import android.text.TextUtils;
import android.util.Log;


import com.lzy.okgo.OkGo;
import com.lzy.okgo.cookie.CookieJarImpl;
import com.lzy.okgo.cookie.store.SPCookieStore;
import com.lzy.okgo.model.Response;


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.net.Proxy;
import java.util.HashSet;
import java.util.Set;


import okhttp3.OkHttpClient;

/**
 * Created by cxy on 2017/11/20.
 */

public class App extends Application {

    public static App instance;


    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
//                .proxy(Proxy.NO_PROXY);
        builder.cookieJar(new CookieJarImpl(new SPCookieStore(this)));
//        builder.addInterceptor(new JeckInterceptor());
        OkGo.getInstance().init(this)                       //必须调用初始化
                .setOkHttpClient(builder.build());


        Context context = getApplicationContext();
// 获取当前包名
        String packageName = context.getPackageName();
// 获取当前进程名
        String processName = getProcessName(android.os.Process.myPid());

    }

    /**
     * 获取进程号对应的进程名
     *
     * @param pid 进程号
     * @return 进程名
     */
    private static String getProcessName(int pid) {
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader("/proc/" + pid + "/cmdline"));
            String processName = reader.readLine();
            if (!TextUtils.isEmpty(processName)) {
                processName = processName.trim();
            }
            return processName;
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException exception) {
                exception.printStackTrace();
            }
        }
        return null;
    }


    public static App getInstance() {
        return instance;
    }


}
